package com.TeacherInfoServer.mapper;

import com.TeacherInfoServer.pojo.DTO.SearchDTO.LearningExperienceSearchDTO;
import com.TeacherInfoServer.pojo.entity.LearningExperience;
import com.TeacherInfoServer.pojo.vo.LearningExperienceListVo;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

public interface LearningExperienceMapper extends BaseMapper<LearningExperience> {
    @Select("SELECT l.*, ty.value as degreeValue, t.teacher_name as teacherName " +
            "FROM learning_experience l " +
            "LEFT JOIN type_info ty ON l.degree = ty.id " +
            "LEFT JOIN teacher t ON l.teacher_id = t.teacher_id "
    )
    Page<LearningExperienceListVo> getLearningExperienceByPage(Page<?> page, @Param("qw") QueryWrapper<LearningExperience> queryWrapper);



    @Select("SELECT l.*, ty.value as degreeValue, t.teacher_name as teacherName " +
            "FROM learning_experience l " +
            "LEFT JOIN type_info ty ON l.degree = ty.id " +
            "LEFT JOIN teacher t ON l.teacher_id = t.teacher_id "
    )
    List<LearningExperienceListVo> getLearningExperienceList();


    @Select("<script>" +
            "SELECT l.*, ty.value as degreeValue, t.teacher_name as teacherName " +
            "FROM learning_experience l " +
            "LEFT JOIN type_info ty ON l.degree = ty.id " +
            "LEFT JOIN teacher t ON l.teacher_id = t.teacher_id " +
            "<where> " +
            "<if test='search.teacherId != null and search.teacherId.trim() != \"\"'> " +
            "AND l.teacher_id LIKE CONCAT('%', #{search.teacherId}, '%') " +
            "</if> " +
            "<if test='search.teacherName != null and search.teacherName.trim() != \"\"'> " +
            "AND t.teacher_name LIKE CONCAT('%', #{search.teacherName}, '%') " +
            "</if> " +
            "<if test='search.degreeValue != null and search.degreeValue.trim() != \"\"'> " +
            "AND ty.value LIKE CONCAT('%', #{search.degreeValue}, '%') " +
            "</if> " +
            "<if test='search.graduationSchool != null and search.graduationSchool.trim() != \"\"'> " +
            "AND l.graduation_school LIKE CONCAT('%', #{search.graduationSchool}, '%') " +
            "</if> " +
            "<if test='search.major != null and search.major.trim() != \"\"'> " +
            "AND l.major LIKE CONCAT('%', #{search.major}, '%') " +
            "</if> " +
            "<if test='search.graduationDate != null and search.graduationDate.trim() != \"\"'> " +
            "AND l.graduation_date LIKE CONCAT('%', #{search.graduationDate}, '%') " +
            "</if> " +
            "</where> " +
            "</script>")
    Page<LearningExperienceListVo> searchLearningExperienceList(Page<?> page, @Param("search") LearningExperienceSearchDTO search);
}